package com.eco.fanliapp.job.goodsjob;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppCompany;
import com.eco.fanliapp.entity.AppGoods;
import com.eco.fanliapp.entity.SySwitch;
import com.eco.fanliapp.service.*;
import com.eco.fanliapp.utils.DateFormatUtils;
import com.eco.fanliapp.utils.StringUtils;
import com.eco.fanliapp.vo.AppGoodsFailure;
import com.eco.fanliapp.vo.TbkItemInfoGetInfo;
import org.apache.commons.lang3.time.DateUtils;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.client.RestTemplate;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;

/**
 * 创建商品索引
 */
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class CreateIndexTask implements Job, Serializable {


    private static final Logger log = LoggerFactory.getLogger(CreateIndexTask.class);

    @Autowired
    private RestTemplate restTemplate;

    public CreateIndexTask() {
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        //取得job详情
        JobDetail jobDetail = context.getJobDetail();

        JobDataMap dataMap = jobDetail.getJobDataMap();

        int executeCount = 0;
        if (dataMap.containsKey("runCount")) {
            executeCount = dataMap.getInt("runCount");
        }

        // 增量计数并将其存储回 JobDataMap，这样可以适当保持工作状态
        executeCount++;
        dataMap.put("runCount", executeCount);

        long startTime = System.currentTimeMillis();
        log.info("***************************************开始执行定时任务-创建商品索引-CreateIndexTask：executeCount=" + executeCount + "--startTime=" + startTime);

        restTemplate.postForObject("http://service-provider" + "/lucene/Index/createIndex", null, String.class);

        long endTime = System.currentTimeMillis();
        log.info("***************************************结束执行定时任务-创建商品索引-CreateIndexTask：executeCount=" + executeCount + "--endTime=" + endTime + "--耗时=" + (endTime - startTime));


    }

}
